/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved.
 */
package com.icinfo.cloud.provider.punish.ucase.urge.controller;

import com.icinfo.cloud.provider.punish.ucase.urge.dto.CaseUrgeAddDto;
import com.icinfo.cloud.provider.punish.ucase.urge.dto.CaseUrgeDetailDto;
import com.icinfo.cloud.provider.punish.ucase.urge.dto.CaseUrgePageRequest;
import com.icinfo.cloud.provider.punish.ucase.urge.dto.CaseUrgePageResponse;
import com.icinfo.cloud.provider.punish.ucase.urge.service.ICaseUrgeHisService;
import com.icinfo.cloud.common.core.page.PageResponse;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.web.BaseController;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 描述: 案件催办记录 case_urge_his 对应的Controller类.<br>
 *
 * @author framework generator
 * @date 2022年11月21日
 */
@RestController
@RequestMapping("/punish/ucase/caseUrge")
public class CaseUrgeHisController extends BaseController {
    /**
     * 日志记录器
     */
    private static final Logger logger = LoggerFactory.getLogger(CaseUrgeHisController.class);

    @Autowired
    private ICaseUrgeHisService caseUrgeHisService;

    /**
     * 案件催办页面
     * @param request
     * @return
     */
    @PostMapping("/caseUrgePage")
    public Result<PageResponse<CaseUrgePageResponse>> caseUrgePage(@RequestBody CaseUrgePageRequest request){
        List<CaseUrgePageResponse> list = caseUrgeHisService.caseUrgePage(request);
        return Result.success(new PageResponse<>(list));
    }

    /**
     * 添加案件催办
     * @author liyafeng
     * @date 2022/10/18
     * @param dto
     * @return {@link Result< String>}
     */
    @PostMapping("/addCaseUrge")
    public Result<String> addCaseUrge(@RequestBody @Validated CaseUrgeAddDto dto) {
        int num = caseUrgeHisService.addCaseUrge(dto);
        if(num>0){
            return Result.success("添加成功");
        }
        return Result.error("添加失败");
    }

    /**
     * 获取案件催办详情
     * @param caseId
     * @return
     */
    @GetMapping("/caseUrgeDetail")
    public Result<List<CaseUrgeDetailDto>> caseUrgeDetail(@RequestParam("caseId") String caseId){
        if (StringUtils.isBlank(caseId)){
            return Result.error("caseId不能为空");
        }
        List<CaseUrgeDetailDto> list = caseUrgeHisService.getCaseUrgeDetail(caseId);
        return Result.success(list);
    }
}
